<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .main ul li {
        	background-color: #fff;
        	border-bottom: 1px solid #e8e8e8;
        }
        .main ul li:first-child {
        	margin-bottom: 6px;
        	border-bottom: none;
        }
        .main ul li:last-child {
        	border-bottom: none;
        }
        .main ul li .li_box {
        	height: 50px;
        	line-height: 50px;
        	display: -webkit-box;
        	display: -webkit-flex;
        	padding-left: 15px;
        }
        .main ul li .li_box .li_boxl {
        	padding-right: 10px;
        }
        .main ul li .li_box .li_boxr {
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	text-align: right;
        }
        .main ul li .li_box .li_boxr span {
        	color: #999;
        	font-size: 14px;
        	display: inline-block;
        	padding-right: 15px;
        }
        .main ul li .li_box .li_boxr input {
        	width: 100%;
        	height: 100%;
        	color: #999;
        	font-size: 14px;
        	padding: 0 15px;
        	box-sizing: border-box;
        	text-align: right;
        }
        .main ul li .li_box .li_boxr input::-webkit-input-placeholder {
        	color: #999;
        }
    </style>
</head>
<body>
    <div class="main">
    	<ul>
    		<li>
    			<div class="li_box">
    				<div class="li_boxl">当前手机号</div>
    				<div class="li_boxr">
    					<span class="phone">&nbps;</span>
    				</div>
    			</div>
    		</li>
    		<li>
    			<div class="li_box">
    				<div class="li_boxl">旧密码</div>
    				<div class="li_boxr">
    					<input type="password" class="old_password" placeholder="请输入旧密码">
    				</div>
    			</div>
    		</li>
    		<li>
    			<div class="li_box">
    				<div class="li_boxl">新密码</div>
    				<div class="li_boxr">
    					<input type="password" class="new_password" placeholder="请输入新密码">
    				</div>
    			</div>
    		</li>
    		<li>
    			<div class="li_box">
    				<div class="li_boxl">确认新密码</div>
    				<div class="li_boxr">
    					<input type="password" class="confirm_password" placeholder="请再次确认新密码">
    				</div>
    			</div>
    		</li>
    	</ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){
        staffData = $api.getStorage('staff_data');
        if(staffData && staffData.phone){
            $(".phone").html(staffData.phone);
        }
        api.addEventListener({
            name: 'confirmModifyEvent'
        }, function(ret, err){
            if( ret ){
                toRevisePassword();
            }
        });

    };

    function toRevisePassword () {
        var old_password = $(".old_password").val();
        var new_password = $(".new_password").val();
        var confirm_password = $(".confirm_password").val();
        if(!old_password){
            toast('旧密码不能为空');
        }else if(!new_password){
            toast('新密码不能为空');
        }else if(new_password != confirm_password){
            toast('两次密码输入不一致');
        }else if(new_password.length < 6){
            toast('密码长度不可少于6位');
        }else{
            openLoading();
            api.ajax({
                url: rootPath + '/api/staff/revise_password',
                method: 'post',
                data: {
                    values: { 
                        staff_id: staffData.id,
                        staff_token: staffData.token,
                        old_password: old_password,
                        new_password: new_password,
                    },
                }
            }, function(ret, err) {
                if (ret) {
                    if(ret.status == 200){
                        toast('修改成功');
                        setTimeout(function(){
                            api.closeWin();
                        },300);
                    }else if(ret.status == 201){
                        toast('旧密码输入错误');
                    }
                } else {
                    
                }
                closeLoading();
            });
        }
    };



</script>
</html>